package tpf.designer.pattern.course5.structure_pattern2.flyweight_13.compound;


import java.util.HashMap;
import java.util.Map;

public class ConcreteCompositeFlyweight implements Flyweight {

    private HashMap flies = new HashMap(10);
    private Flyweight flyweight;

    public ConcreteCompositeFlyweight() {
    }

    /**
     * 添加一个新的单纯享元对象到聚集中
     * @param key
     * @param fly
     */
    public void add(Character key, Flyweight fly){
        flies.put(key,fly);
    }

    /**
     * 外蕴状态作为参量传入方法
     * @param state
     */
    @Override
    public void operation(String state) {
        Flyweight fly;
        for (Object o : flies.entrySet()) {
            Map.Entry e = (Map.Entry) o;
            fly = (Flyweight) e.getValue();
            fly.operation(state);
        }
    }
}
